package cc.codeshop.net;

import java.io.File;

import android.content.Context;
import android.os.Environment;

public class FileUtil {

	public static File getCacheDir(Context context, String subPath) {
		File dir;
		if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
			dir = new File(Environment.getExternalStorageDirectory(), context.getPackageName() + "/cache/" + subPath);
		} else {
			dir = new File(context.getCacheDir(), subPath);
		}
		if (!dir.exists()) {
			dir.mkdirs();
		}
		return dir;
	}

	public static File getCacheFile(Context context, String subPath, String fileName) {
		File cacheDir = getCacheDir(context, subPath);
		return getCacheFile(cacheDir, fileName);
	}

	public static File getCacheFile(File cacheDir, String fileName) {
		return new File(cacheDir, fileName);
	}
	
}
